package com.example.task1.ui.AllService.EventManagement;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.EventCommentBean;
import com.example.task1.ui.BaseAdapter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class EventCommentAdapter extends BaseAdapter<EventCommentBean.RowsDTO> {

    private List<EventCommentBean.RowsDTO> data = new ArrayList<>();
    private ImageView image;
    private TextView tvName;
    private TextView tvContent;
    private TextView tvTime;

    @Override
    protected void setData(List<EventCommentBean.RowsDTO> rows) {
        int size = data.size();
        data.addAll(rows);
        notifyItemInserted(size);
    }

    protected void addData(List<EventCommentBean.RowsDTO> rows) {
        data.addAll(0,rows);
        notifyItemRangeInserted(0,rows.size());
    }

    @Override
    protected int getLayout() {
        return R.layout.evencommentlist;
    }

    @Override
    protected Context getContext() {
        return null;
    }

    @Override
    protected List<EventCommentBean.RowsDTO> getData() {
        return data;
    }

    @Override
    protected void onBind(myHolder holder, EventCommentBean.RowsDTO date) {
        if (!TextUtils.isEmpty(date.getAvatar())) {
            MyApplication.glide(image, date.getAvatar());
        }
        tvContent.setText(date.getContent());
        tvTime.setText("---" + date.getCommentTime());
        tvName.setText(Objects.nonNull(date.getNickName()) ? date.getNickName() : date.getUserName());
    }

    @Override
    protected void holder(View itemView) {
        initView(itemView);
    }

    private void initView(View itemView) {
        image = (ImageView) itemView.findViewById(R.id.image);
        tvName = (TextView) itemView.findViewById(R.id.tv_name);
        tvContent = (TextView) itemView.findViewById(R.id.tv_content);
        tvTime = (TextView) itemView.findViewById(R.id.tv_time);
    }
}
